<?php
/*
  +-----------------------------------------------------------------------------------------+
  | Projeto MonitoraSUS                                                                     |
  +-----------------------------------------------------------------------------------------+
  | Copyright (c) 2005-2008 Secretaria Municipal de Saúde de Belo Horizonte / Prodabel      |
  |                                                                                         |
  | Analista Responsvel: Hugo Nathaniel Rodrigues <hugonr@gmail.com>, <hugo@pbh.gov.br> |
  |                       Consultor - GSFS - Prodabel / SMSA                                |
  | Departamento Responsável - SMSA: GPLD - Paulinho <pauloces@pbh.gov.br>                  |
  | Departamento Responsável - Prodabel: GSFS - Ricardo Monteiro <monteiro@pbh.gov.br>      |
  | Analista de Informaao: Marcone <marcone.costa@pbh.gov.br>                              |
  +-----------------------------------------------------------------------------------------+
 */

/**
 * header include para todas as pginas do MonitoraSUS. Este script ser incluido sempre no
 * inicio de cada página do MonitoraSUS
 *
 * @author Hugo Nathaniel Rodrigues <hugonr@gmail.com> <hugo@pbh.gov.br>
 * @version $Id: inc.header.php,v 1.0 08/07/2008 10:34:00 Hugo $
 *
 * @package MonitoraSUS
 */
require_once("./dados/inc.config.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>MonitoraSUS</title>
        <link href="./telas/styles/estilos.css" rel="stylesheet" type="text/css"/>

        <!--[if IE]>
        <style type="text/css" media="screen">
        body {
        font-size: 100%; /* enable IE to resize em fonts */
        }
        #menu{
	background-image:url();
        }
        #menu ul li {
        float: left; /* cure IE5.x "whitespace in lists" problem */
        width: 100%;
        }
        #menu ul li a {
        height: 1%; /* make links honour display: block; properly */
        }

        #menu a, #menu h2 {
        font: bold 0.7em/1.4em arial, helvetica, sans-serif;
        /* if required use em's for IE as it won't resize pixels */
        }
        </style>
        <![endif]-->

        <script language="javascript">

            function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
            {
                var marked_row = new Array;

                var theCells = null;

                // 1. Pointer and mark feature are disabled or the browser can't get the
                //    row -> exits
                if ((thePointerColor == '' && theMarkColor == '')
                    || typeof(theRow.style) == 'undefined') {
                    return false;
                }

                // 1.1 Sets the mouse pointer to pointer on mouseover and back to normal otherwise.
                if (theAction == "over" || theAction == "click") {
                    theRow.style.cursor='pointer';
                } else {
                    theRow.style.cursor='default';
                }

                // 2. Gets the current row and exits if the browser can't get it
                if (typeof(document.getElementsByTagName) != 'undefined') {
                    theCells = theRow.getElementsByTagName('td');
                }
                else if (typeof(theRow.cells) != 'undefined') {
                    theCells = theRow.cells;
                }
                else {
                    return false;
                }

                // 3. Gets the current color...
                var rowCellsCnt  = theCells.length;
                var domDetect    = null;
                var currentColor = null;
                var newColor     = null;
                // 3.1 ... with DOM compatible browsers except Opera that does not return
                //         valid values with "getAttribute"
                if (typeof(window.opera) == 'undefined'
                    && typeof(theCells[0].getAttribute) != 'undefined') {
                    currentColor = theCells[0].getAttribute('bgcolor');
                    domDetect    = true;
                }
                // 3.2 ... with other browsers
                else {
                    currentColor = theCells[0].style.backgroundColor;
                    domDetect    = false;
                } // end 3

                // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
                if (currentColor.indexOf("rgb") >= 0)
                {
                    var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                    currentColor.indexOf(')'));
                    var rgbValues = rgbStr.split(",");
                    currentColor = "#";
                    var hexChars = "0123456789ABCDEF";
                    for (var i = 0; i < 3; i++)
                    {
                        var v = rgbValues[i].valueOf();
                        currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
                    }
                }

                // 4. Defines the new color
                // 4.1 Current color is the default one
                if (currentColor == ''
                    || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
                    if (theAction == 'over' && thePointerColor != '') {
                        newColor              = thePointerColor;
                    }
                    else if (theAction == 'click' && theMarkColor != '') {
                        newColor              = theMarkColor;
                        marked_row[theRowNum] = true;
                        // Garvin: deactivated onclick marking of the checkbox because it's also executed
                        // when an action (like edit/delete) on a single item is performed. Then the checkbox
                        // would get deactived, even though we need it activated. Maybe there is a way
                        // to detect if the row was clicked, and not an item therein...
                        // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
                    }
                }
                // 4.1.2 Current color is the pointer one
                else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
                    && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
                    if (theAction == 'out') {
                        newColor              = theDefaultColor;
                    }
                    else if (theAction == 'click' && theMarkColor != '') {
                        newColor              = theMarkColor;
                        marked_row[theRowNum] = true;
                        // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
                    }
                }
                // 4.1.3 Current color is the marker one
                else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
                    if (theAction == 'click') {
                        newColor              = (thePointerColor != '')
                            ? thePointerColor
                        : theDefaultColor;
                        marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                            ? true
                        : null;
                        // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
                    }
                } // end 4

                // 5. Sets the new color...
                if (newColor) {
                    var c = null;
                    // 5.1 ... with DOM compatible browsers except Opera
                    if (domDetect) {
                        for (c = 0; c < rowCellsCnt; c++) {
                            theCells[c].setAttribute('bgcolor', newColor, 0);
                        } // end for
                    }
                    // 5.2 ... with other browsers
                    else {
                        for (c = 0; c < rowCellsCnt; c++) {
                            theCells[c].style.backgroundColor = newColor;
                        }
                    }
                } // end 5

                return true;
            } // end of the 'setPointer()' function


            // função para consistência de datas.
            function check_date(field){
                var checkstr = "0123456789";
                var DateField = field;
                var Datevalue = "";
                var DateTemp = "";
                var seperator = "/";
                var day;
                var month;
                var year;
                var leap = 0;
                var err = 0;
                var i;
                err = 0;
                DateValue = DateField.value;
                /* Delete all chars except 0..9 */
                for (i = 0; i < DateValue.length; i++) {
                    if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
                        DateTemp = DateTemp + DateValue.substr(i,1);
                    }
                }
                DateValue = DateTemp;
                /* Always change date to 8 digits - string*/
                /* if year is entered as 2-digit / always assume 20xx */
                if (DateValue.length == 6) {
                    DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
                if (DateValue.length != 8) {
                    err = 19;}
                /* year is wrong if year = 0000 */
                year = DateValue.substr(4,4);
                if (year == 0) {
                    err = 20;
                }
                /* Validation of month*/
                month = DateValue.substr(2,2);
                if ((month < 1) || (month > 12)) {
                    err = 21;
                }
                /* Validation of day*/
                day = DateValue.substr(0,2);
                if (day < 1) {
                    err = 22;
                }
                /* Validation leap-year / february / day */
                if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
                    leap = 1;
                }
                if ((month == 2) && (leap == 1) && (day > 29)) {
                    err = 23;
                }
                if ((month == 2) && (leap != 1) && (day > 28)) {
                    err = 24;
                }
                /* Validation of other months */
                if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
                    err = 25;
                }
                if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
                    err = 26;
                }
                /* if 00 ist entered, no error, deleting the entry */
                if ((day == 0) && (month == 0) && (year == 00)) {
                    err = 0; day = ""; month = ""; year = ""; seperator = "";
                }
                /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
                if (err == 0) {
                    DateField.value = day + seperator + month + seperator + year;
                }
                /* Error-message if err != 0 */
                else {
                    alert("Data Inválida!!!");
                    DateField.select();
                    DateField.focus();
                }
            }

            function janelaeditor(numindicador)
            {
                testwindow= window.open ("./telas/inc.editor.php?ind=" + numindicador, "Indicador",
                "location=1,status=1,scrollbars=1,toolbar=no,width=800,height=600");
                testwindow.moveTo(0,0);
            }

            function menurelatorio(menu){
                window.open("./telas/inc.menurelatorio.php?menu=" + menu , '' , 'resizable=yes,scrollbars=yes,status=yes,directories=no,toolbar=yes,width=790,height=510,screenX=100,screenY=0,top=0,left=0');
            }

            function favoritos(){
                window.open("./telas/inc.favoritos.php", '' , 'resizable=yes,scrollbars=yes,status=yes,directories=no,toolbar=yes,width=790,height=510,screenX=100,screenY=0,top=0,left=0');
            }

            function grafico(s_des_indicador, indicador){
                window.open("./telas/inc.graficoflash.php?titulo=" + s_des_indicador + "&indicador=" + indicador , '' , 'resizable=yes,scrollbars=yes,status=yes,directories=no,toolbar=yes,width=790,height=510,screenX=100,screenY=0,top=0,left=0');
            }

            function grafico2(s_des_indicador, indicador){
                window.open("./telas/inc.graficoflash2.php?titulo=" + s_des_indicador + "&indicador=" + indicador , '' , 'resizable=yes,scrollbars=yes,status=yes,directories=no,toolbar=yes,width=790,height=510,screenX=100,screenY=0,top=0,left=0');
            }

            function grafico3(s_des_indicador, indicador){
                window.open("./telas/inc.graficoflash3.php?titulo=" + s_des_indicador + "&indicador=" + indicador , '' , 'resizable=yes,scrollbars=yes,status=yes,directories=no,toolbar=yes,width=790,height=510,screenX=100,screenY=0,top=0,left=0');
            }


            function excluir(menu){
                if (confirm("Deseja mesmo apagar este registro?")){
                    document.telalogin.action = "./index.php?current=&menu=" + menu + "&acao=ex";
                    document.telalogin.submit();
                }
            }

            function arquivar(menu){
                if (confirm("Deseja mesmo arquivar este registro?")){
                    document.telalogin.action = "./index.php?current=&menu=" + menu + "&acao=ar";
                    document.telalogin.submit();
                }
            }

            function adicionainstrumento(menu, indicador){
                document.telalogin.action = "./index.php?current=&menu=" + menu + "&ind=" + indicador + "&acao=adinstrumento&inst=" + document.mostraindicador.codinstrumento.value;
                document.telalogin.submit();
            }

            function adicionadestaque(menu, indicador){
                document.telalogin.action = "./index.php?current=&menu=" + menu + "&ind=" + indicador + "&acao=addestaque&inst=" + document.mostraindicador.numdestaque.value;
                document.telalogin.submit();
            }

            function excluirinstrumento(menu, indicador, instrumento){
                document.telalogin.action = "./index.php?current=&menu=" + menu + "&ind=" + indicador + "&acao=exinstrumento&inst=" + instrumento;
                document.telalogin.submit();
            }


        </script>
    </head>
    <body >
        <?php include("./telas/inc.banner.php"); ?>
        <div id="corpo">
            <div id="topo">


                <?php
// conexao com o banco de dados;
                require_once("./dados/class.Conector.php");
                $conexao = new Conector;
                $conexao->conectar($servidorbanco, $loginbanco, $senhabanco, $bancodedados);
// apresentação de mensagens e alertas
                require_once("./telas/inc.mensagem.php");
// codificação de texto
                require_once("./sistema/inc.convertcharset.php");

                include("./telas/inc.login.php");
                include("./sistema/inc.conteudo.php"); //Hugo Leonardo - 02052012 - TESTE DISTRITO
                include("./telas/inc.menu.php");

                if ($servidorbanco == "ipatinga") {
                    echo "<br>Atenção!!! SISTEMA EM SERVIDOR DE DESENVOLVIMENTO!!!";
                }
                $conexao->desconectar();
                ?>
                
            </div>
        </div>        
    </body>
</html>

